package com.szly.phm.admin.controller;

import com.szly.phm.admin.aspectj.annotation.OperationLogAnnotation;
import com.szly.phm.admin.aspectj.enums.ModuleEnum;
import com.szly.phm.admin.aspectj.enums.OperationActionEnum;
import com.szly.phm.admin.utils.CustomResponse;
import com.szly.phm.admin.utils.SecurityUtils;
import com.szly.phm.common.entity.dto.fi.*;
import com.szly.phm.common.entity.dto.user.LoginUserDTO;
import com.szly.phm.common.entity.result.RootResponse;
import com.szly.phm.common.entity.vo.fi.DisplayLocationInfoPageChildDTO;
import com.szly.phm.common.service.IFiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

@RestController
@Validated
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping("/pc/fi")
@Api(tags = "文件数据管理")
public class FiController {
    private final IFiService iFiService;

    @ApiOperation(value = "添加显示位置")
    @OperationLogAnnotation(getModuleName = ModuleEnum.FILE_DATA,getOperationAction = OperationActionEnum.SAVE)
    @PostMapping("/v1/displayLocationInfos")
    @CustomResponse
    public RootResponse createDisplayLocationInfo(@Valid @RequestBody CreateDisplayLocationInfoDTO createDisplayLocationInfoDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iFiService.createDisplayLocationInfo(createDisplayLocationInfoDTO,userDTO);
    }
    @ApiOperation(value = "查询显示位置")
    @GetMapping("/v1/displayLocationInfos")
    @CustomResponse
    public RootResponse selectDisplayLocationInfo(@Valid DisplayLocationInfoPageDTO displayLocationInfoPageDTO) {
        return iFiService.queryDisplayLocationInfoPage(displayLocationInfoPageDTO);
    }
    @ApiOperation(value = "查询显示位置子级")
    @GetMapping("/v1/displayLocationInfosChild")
    @CustomResponse
    public RootResponse selectDisplayLocationInfosChild(@Valid DisplayLocationInfoPageChildDTO displayLocationInfoPageDTO) {
        return iFiService.queryDisplayLocationInfosChildPage(displayLocationInfoPageDTO);
    }
    @ApiOperation(value = "删除显示位置")
    @OperationLogAnnotation(getModuleName = ModuleEnum.FILE_DATA,getOperationAction = OperationActionEnum.UPDATE)
    @DeleteMapping("/v1/displayLocationInfos")
    @CustomResponse
    public RootResponse deleteDisplayLocationInfo(@NotBlank(message = "Id不能为空") @RequestParam(value = "id") String id) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iFiService.deleteDisplayLocationInfo(id,userDTO);
    }
    @ApiOperation(value = "修改显示位置")
    @OperationLogAnnotation(getModuleName = ModuleEnum.FILE_DATA,getOperationAction = OperationActionEnum.UPDATE)
    @PutMapping("/v1/displayLocationInfos")
    @CustomResponse
    public RootResponse updateDisplayLocationInfo(@Valid @RequestBody UpdateDisplayLocationInfoDTO updateServerArea) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iFiService.updateDisplayLocationInfo(updateServerArea,userDTO);
    }


    @ApiOperation(value = "添加子系统状态")
    @OperationLogAnnotation(getModuleName = ModuleEnum.FILE_DATA,getOperationAction = OperationActionEnum.SAVE)
    @PostMapping("/v1/fiSubsystemStatusDatas")
    @CustomResponse
    public RootResponse createFiSubsystemStatusData(@Valid @RequestBody CreateFiSubsystemStatusDataDTO createMajorDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iFiService.createFiSubsystemStatusData(createMajorDTO,userDTO);
    }
    @ApiOperation(value = "查询子系统状态")
    @GetMapping("/v1/fiSubsystemStatusDatas")
    @CustomResponse
    public RootResponse selectFiSubsystemStatusData(@Valid FiSubsystemStatusDataPageDTO serverAreaPageDTO) {
        return iFiService.selectFiSubsystemStatusData(serverAreaPageDTO);
    }
    @ApiOperation(value = "删除子系统状态")
    @OperationLogAnnotation(getModuleName = ModuleEnum.FILE_DATA,getOperationAction = OperationActionEnum.UPDATE)
    @DeleteMapping("/v1/fiSubsystemStatusDatas")
    @CustomResponse
    public RootResponse deleteServerAreas(@NotBlank(message = "Id不能为空") @RequestParam(value = "id") String id) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iFiService.deleteFiSubsystemStatusData(id,userDTO);
    }
    @ApiOperation(value = "修改子系统状态")
    @OperationLogAnnotation(getModuleName = ModuleEnum.FILE_DATA,getOperationAction = OperationActionEnum.UPDATE)
    @PutMapping("/v1/fiSubsystemStatusDatas")
    @CustomResponse
    public RootResponse updateFiSubsystemStatusData(@Valid @RequestBody UpdateFiSubsystemStatusDataDTO updateServerArea) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iFiService.updateFiSubsystemStatusData(updateServerArea,userDTO);
    }
    @ApiOperation(value = "添加数据类型")
    @OperationLogAnnotation(getModuleName = ModuleEnum.FILE_DATA,getOperationAction = OperationActionEnum.SAVE)
    @PostMapping("/v1/fiDataTypes")
    @CustomResponse
    public RootResponse createFiDataType(@Valid @RequestBody CreateFiDataTypeDTO createMajorDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iFiService.createFiDataType(createMajorDTO,userDTO);
    }
    @ApiOperation(value = "查询数据类型")
    @GetMapping("/v1/fiDataTypes")
    @CustomResponse
    public RootResponse selectFiDataType(@Valid FiDataTypePageDTO serverAreaPageDTO) {
        return iFiService.selectFiDataType(serverAreaPageDTO);
    }
    @ApiOperation(value = "删除数据类型")
    @OperationLogAnnotation(getModuleName = ModuleEnum.FILE_DATA,getOperationAction = OperationActionEnum.UPDATE)
    @DeleteMapping("/v1/fiDataTypes")
    @CustomResponse
    public RootResponse deleteFiDataType(@NotBlank(message = "Id不能为空") @RequestParam(value = "id") String id) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iFiService.deleteFiDataType(id,userDTO);
    }
    @ApiOperation(value = "修改数据类型")
    @OperationLogAnnotation(getModuleName = ModuleEnum.FILE_DATA,getOperationAction = OperationActionEnum.UPDATE)
    @PutMapping("/v1/fiDataTypes")
    @CustomResponse
    public RootResponse updateFiDataType(@Valid @RequestBody UpdateFiDataTypeDTO updateServerArea) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iFiService.updateFiDataType(updateServerArea,userDTO);
    }
    @ApiOperation(value = "添加实时文件结构")
    @OperationLogAnnotation(getModuleName = ModuleEnum.FILE_DATA,getOperationAction = OperationActionEnum.SAVE)
    @PostMapping("/v1/fiRealTimeFileStructures")
    @CustomResponse
    public RootResponse createFiRealTimeFileStructure(@Valid @RequestBody CreateFiRealTimeFileStructureDTO createMajorDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iFiService.createFiRealTimeFileStructure(createMajorDTO,userDTO);
    }
    @ApiOperation(value = "查询实时文件结构")
    @GetMapping("/v1/fiRealTimeFileStructures")
    @CustomResponse
    public RootResponse selectFiRealTimeFileStructure(@Valid FiRealTimeFileStructurePageDTO serverAreaPageDTO) {
        return iFiService.selectFiRealTimeFileStructure(serverAreaPageDTO);
    }



    @ApiOperation(value = "删除实时文件结构")
    @OperationLogAnnotation(getModuleName = ModuleEnum.FILE_DATA,getOperationAction = OperationActionEnum.UPDATE)
    @DeleteMapping("/v1/fiRealTimeFileStructures")
    @CustomResponse
    public RootResponse deleteFiRealTimeFileStructure(@NotBlank(message = "Id不能为空") @RequestParam(value = "id") String id) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iFiService.deleteFiRealTimeFileStructure(id,userDTO);
    }
    @ApiOperation(value = "修改实时文件结构")
    @OperationLogAnnotation(getModuleName = ModuleEnum.FILE_DATA,getOperationAction = OperationActionEnum.UPDATE)
    @PutMapping("/v1/fiRealTimeFileStructures")
    @CustomResponse
    public RootResponse updateFiRealTimeFileStructure(@Valid @RequestBody UpdateFiRealTimeFileStructureDTO updateServerArea) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iFiService.updateFiRealTimeFileStructure(updateServerArea,userDTO);
    }
    @ApiOperation(value = "添加文件类型")
    @OperationLogAnnotation(getModuleName = ModuleEnum.FILE_DATA,getOperationAction = OperationActionEnum.SAVE)
    @PostMapping("/v1/fiFileTypes")
    @CustomResponse
    public RootResponse createFiFileType(@Valid @RequestBody CreateFiFileTypeDTO createMajorDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iFiService.createFiFileType(createMajorDTO,userDTO);
    }
    @ApiOperation(value = "查询文件类型")
    @GetMapping("/v1/fiFileTypes")
    @CustomResponse
    public RootResponse selectFiFileType(@Valid FiFileTypePageDTO serverAreaPageDTO) {
        return iFiService.selectFiFileType(serverAreaPageDTO);
    }
    @ApiOperation(value = "删除文件类型")
    @OperationLogAnnotation(getModuleName = ModuleEnum.FILE_DATA,getOperationAction = OperationActionEnum.UPDATE)
    @DeleteMapping("/v1/fiFileTypes")
    @CustomResponse
    public RootResponse deleteFiFileType(@NotBlank(message = "Id不能为空") @RequestParam(value = "id") String id) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iFiService.deleteFiFileType(id,userDTO);
    }
    @ApiOperation(value = "修改文件类型")
    @OperationLogAnnotation(getModuleName = ModuleEnum.FILE_DATA,getOperationAction = OperationActionEnum.UPDATE)
    @PutMapping("/v1/fiFileTypes")
    @CustomResponse
    public RootResponse updateFiFileType(@Valid @RequestBody UpdateFiFileTypeDTO updateServerArea) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iFiService.updateFiFileType(updateServerArea,userDTO);
    }
    @ApiOperation(value = "添加模型关联的实时文件结构")
    @OperationLogAnnotation(getModuleName = ModuleEnum.FILE_DATA,getOperationAction = OperationActionEnum.SAVE)
    @PostMapping("/v1/fiTaRelations")
    @CustomResponse
    public RootResponse createFiTaRelation(@Valid @RequestBody CreateFiTaRelation createMajorDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iFiService.createFiTaReLation(createMajorDTO,userDTO);
    }
    @ApiOperation(value = "根据算法模型查询文件结构")
    @GetMapping("/v1/selectRealTimeFileStructures")
    @CustomResponse
    public RootResponse selectRealTimeFileStructures(@NotBlank(message = "Id不能为空") @RequestParam(value = "modelId") String modelId) {
        return iFiService.selectRealTimeFileStructures(modelId);
    }

}
